package com.example.springbott.config;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @author 1784549954@qq.com
 * @since 2022/11/21 18:20
 */
public class MarketSessionManager extends DefaultWebSessionManager {
    private static final String MARKET_ADMIN_TOKEN="X-CskaoyanMarket-Admin-Token";
    private static final String MARKET_WX_TOKEN="X-CskaoyanMarket-Token";


    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest req = (HttpServletRequest) request;
        String sessionId = req.getHeader(MARKET_ADMIN_TOKEN);
        if (sessionId != null & !"".equals(sessionId)){
            return sessionId;
        }
        String sessionId2 = req.getHeader(MARKET_WX_TOKEN);
        if (sessionId2 != null & !"".equals(sessionId)){
            return sessionId2;
        }
        return super.getSessionId(request,response);
    }
}
